/// @Classname : HcElevatedButton
/// @Author :
/// @Time : 2023-11-14 14:32
/// @Description : 有边框 有颜色 有点击效果的按钮

import 'package:flutter/material.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/theme/hc_button_theme.dart';
import 'package:hc_ui/theme/hc_common_theme.dart';
import 'package:hc_ui/utils/hc_color_util.dart';
import 'package:hc_ui/widget/button/hc_base_button.dart';

class HcElevatedButton extends StatelessWidget {
  final double elevation;
  final VoidCallback? onPressed;
  final VoidCallback? longPress;
  final String text;
  final bool disabled;
  final bool loading;
  final Widget? child;
  final Color? backgroundColor;
  final Color? disabledBackgroundColor;
  final Color? textColor;
  final Color? disabledTextColor;
  final Color? splashColor;
  final Color? highlightColor;
  final BorderRadius? borderRadius;
  final double? fontSize;
  final FontWeight? fontWeight;
  final TextStyle? textStyle;
  final Size? minSize;
  final Size? maxSize;

  const HcElevatedButton({
    super.key,
    this.elevation = 2,
    required this.onPressed,
    required this.text,
    this.disabled = false,
    this.loading = false,
    this.child,
    this.longPress,
    this.backgroundColor,
    this.disabledBackgroundColor,
    this.textColor,
    this.disabledTextColor,
    this.splashColor,
    this.highlightColor,
    this.borderRadius,
    this.fontSize,
    this.fontWeight,
    this.textStyle,
    this.minSize,
    this.maxSize,
  });

  @override
  Widget build(BuildContext context) {
    HcCommonTheme comm = HcCustomerConfig().allTheme.commonTheme;
    Color finalBgColor = backgroundColor ?? comm.primaryColor;
    Color surfaceColor = HcColorUtil.needLightColor(finalBgColor)
        ? comm.onSurfaceColor
        : comm.surfaceColor;
    Color finalTextColor = textColor ??
        (HcColorUtil.needLightColor(finalBgColor)
            ? comm.textInverseColor
            : comm.textBaseColor);
    HcButtonTheme? theme = HcButtonTheme(
        fontSize: fontSize,
        miniSize: minSize,
        maxSize: maxSize,
        fontWeight: fontWeight,
        textStyle: textStyle,
        backgroundColor: finalBgColor,
        disabledBackgroundColor: disabledBackgroundColor ??
            finalBgColor.withOpacity(comm.disabledOpacity),
        textColor: finalTextColor,
        borderRadius: borderRadius,
        disabledTextColor: disabledTextColor ??
            finalTextColor.withOpacity(comm.disabledTextOpacity),
        splashColor:
            splashColor ?? surfaceColor.withOpacity(comm.splashOpacity),
        highlightColor:
            highlightColor ?? surfaceColor.withOpacity(comm.highlightOpacity));

    return HcBaseButton(
      elevation: elevation,
      onPressed: onPressed,
      longPress: longPress,
      text: text,
      disabled: disabled,
      loading: loading,
      themeData: theme,
    );
  }
}
